using UnityEngine;

public class CameraSmoothFollow : MonoBehaviour
{
	public Transform target;

	public float distance = 10f;

	public float height = 5f;

	public float rotationDamping;

	public float heightDamping;

	public float zoom = 1f;

	private float _targetDistance;

	private float _targetHeight;

	private Transform _cachedTransform;

	private void Start()
	{
		_cachedTransform = base.transform;
		_targetDistance = distance;
		_targetHeight = height;
	}

	public void LateUpdate()
	{
		if ((bool)target)
		{
			Vector3 eulerAngles = target.eulerAngles;
			float y = eulerAngles.y;
			Vector3 position = target.position;
			float b = position.y + height * zoom;
			Vector3 eulerAngles2 = base.transform.eulerAngles;
			float y2 = eulerAngles2.y;
			Vector3 position2 = base.transform.position;
			float y3 = position2.y;
			y2 = Mathf.LerpAngle(y2, y, rotationDamping * Time.deltaTime);
			y3 = Mathf.Lerp(y3, b, heightDamping * Time.deltaTime);
			Quaternion rotation = Quaternion.Euler(0f, y2, 0f);
			_cachedTransform.position = target.position;
			_cachedTransform.position -= rotation * Vector3.forward * distance * zoom;
			Transform cachedTransform = _cachedTransform;
			Vector3 position3 = base.transform.position;
			float x = position3.x;
			float y4 = y3;
			Vector3 position4 = base.transform.position;
			cachedTransform.position = new Vector3(x, y4, position4.z);
			_cachedTransform.LookAt(target);
			if (Mathf.Abs(_targetDistance - distance) > Mathf.Epsilon)
			{
				distance = Mathf.MoveTowards(distance, _targetDistance, Time.deltaTime * 30f);
			}
			if (Mathf.Abs(_targetHeight - height) > Mathf.Epsilon)
			{
				height = Mathf.MoveTowards(height, _targetHeight, Time.deltaTime * 30f);
			}
		}
	}

	public void SetZoom(float z)
	{
		zoom = z;
	}

	public void SetHeight(float h)
	{
		_targetHeight = h;
	}

	public void SetDistance(float d)
	{
		_targetDistance = d;
	}
}
